<form class="layui-form seller-form" action="">

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label seller-inline-2">学号：</label>
            <div class="layui-input-inline" id="xh_box">
                <input type="text" id="xh" name="xh" class="layui-input" value="" placeholder="请输入学号" ></input>
            </div>
        </div> 
        <div class="layui-inline">
            <label class="layui-form-label seller-inline-2">冻结状态：</label>
            <div class="layui-input-inline" id="status_box">
                <select name="status" lay-filter="status" id="status" lay-search>
                    <option value="1">已冻结</option>
                    <option value="0">已解除冻结</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <button class="layui-btn layui-btn-sm" lay-submit lay-filter="search"><i class="iconfont icon-chaxun"></i>查询</button>
            <button type="button" id="disable" class="layui-btn layui-btn-sm disable"><i class="layui-icon">&#xe608;</i>冻结</button>
            <button type="button" id="enable" class="layui-btn layui-btn-sm enable"><i class="layui-icon">&#xe66d;</i>解除冻结</button>
        </div>

    </div>

</form>

<div class="table-body">
    <table id="wxuserTable" lay-filter="wxuserTable"></table>
</div>

<script>
    layui.use(['table', 'form', 'layer', 'laydate'], function () {
        var layer = layui.layer, table = layui.table, form = layui.form, date = layui.laydate;
        
        var printError = false;
        var printstatus = 1;
        var printindex = 0;
        var myInterval = null;
        var checkedData = new Array();
        //执行渲染
        table.render({
            elem: '#wxuserTable', //指定原始表格元素选择器（推荐id选择器）
            height: 'full-115',
            cellMinWidth: '80',
            page: 'true',
            limit: '20',
            id: 'wxuserTable',
            url: "{:url('BookCommon/returnNull')}",
            cols: [[ //标题栏
                { type: 'checkbox' },
                { field: 'bmmc', sort: true, title: '部/院', width: 200, align: 'center' },
                { field: 'zymc', sort: true, title: '专业', width: 200, align: 'center' },
                { field: 'bjmc', sort: true, title: '班级', width: 200, align: 'center' },
                { field: 'xh', sort: true, title: '学号', width: 200, align: 'center' },
                { field: 'xm', sort: true, title: '姓名', width: 200, align: 'center' },
                {
                    field: 'status', title: '状态', width: 200, align: 'center', templet: function (data) {
                        if(data.status == 1) {
                            html = '<div style="color: #393D49;">已冻结</div>';
                        } else if(data.status == 2) {
                            html = '<div style="color: #009688;">已解除冻结</div>';
                        }
                        return html;
                    }
                }
            ]], //设置表头
            where: {}
            //,…… //更多参数参考右侧目录：基本参数选项
        });

        // 查询
        form.on('submit(search)', function (data) {
            table.reload('wxuserTable', {
                where: data.field,
                page: {curr: 1},
                url: "{:url('Collection/WxUserIndex')}",
            });
            return false;
        });

        // 冻结
        $(document).on('click','.disable',function(){   
            let checkStatus = table.checkStatus('wxuserTable');
            data = checkStatus.data;

            if(data.length==0){
                layer.msg('请先选择数据行！', { time: 1300 });
                return false;
            }

            let xhs = "";
            let flag = true;
            $.each(data, function(index, item){
                if(item.status==1){
                    layer.msg('已冻结，请重新选择！', { time: 1300 });
                    flag = false;
                    return false;
                }
                xhs += item.xh + ",";
            })

            if(flag){
                $('#disable').addClass("layui-btn-disabled");
                $('#disable').attr("disabled", true);
                xhs = xhs.substring(0, xhs.length - 1);
                
                layer.confirm('确定要冻结吗?', {icon: 3, title:'提示'}, function(){
                    JsPost("{:url('Collection/WxUserDisable')}", {xhs:xhs}, function (res) {
                        if(res.status){
                            layui.table.reload('wxuserTable', {
                                page: {curr: 1},
                                url: "{:url('Collection/WxUserIndex')}",
                            });
                        } 
                        layer.msg(res.msg);
                    });
                });
                
                $('#disable').removeClass("layui-btn-disabled");
                $('#disable').removeAttr("disabled"); 
            }
             
            return false;          
        });
 
        // 解除冻结
        $(document).on('click','.enable',function(){   
            let checkStatus = table.checkStatus('wxuserTable');
            data = checkStatus.data;

            if(data.length==0){
                layer.msg('请先选择数据行！', { time: 1300 });
                return false;
            }

            let xhs = "";
            let flag = true;
            $.each(data, function(index, item){
                if(item.status!=1){
                    layer.msg('未冻结，请重新选择！', { time: 1300 });
                    flag = false;
                    return false;
                }
                xhs += item.xh + ",";
            })

            if(flag){
                $('#enable').addClass("layui-btn-disabled");
                $('#enable').attr("disabled", true);
                xhs = xhs.substring(0, xhs.length - 1);
                
                layer.confirm('确定要解除冻结吗?', {icon: 3, title:'提示'}, function(){
                    JsPost("{:url('Collection/WxUserEnable')}", {xhs:xhs}, function (res) {
                        if(res.status){
                            layui.table.reload('wxuserTable', {
                                page: {curr: 1},
                                url: "{:url('Collection/WxUserIndex')}",
                            });
                        } 
                        layer.msg(res.msg);
                    });
                });
                
                $('#enable').removeClass("layui-btn-disabled");
                $('#enable').removeAttr("disabled"); 
            }
             
            return false;          
        });

    });
</script>